# 自动化测试
from selenium import webdriver

import time
# 标准测试库
import unittest


# 声明测试类
class User_LoginTest(unittest.TestCase):

    def setUp(self):
        # 设置驱动  开浏览器
        self.driver = webdriver.Chrome("C:/Users/Administrator/www/chromedriver.exe")


# 邮箱测试
    # 测试邮箱登录        邮箱空
    def test_login_email_null(self):
        drver = self.driver
        # 打开路径
        drver.get("http://localhost:8080/login")

        time.sleep(5)

        # 点击按钮
        drver.find_elements_by_class_name('van-tab__text')[1].click()

        # 标签选择器input标签
        drver.find_elements_by_tag_name('input')[3].send_keys('00000000')

        # 点击按钮
        drver.find_elements_by_class_name('van-button')[2].click()

        time.sleep(2)

    

        # 获取弹框信息div
        div = drver.find_elements_by_class_name("van-toast__text")[0]

        #
        print(div)
        #
        # # 获取文本
        text = div.get_attribute('innerText')
        print(text)
        #
        # # 断言比对
        self.assertEqual(text, '邮箱输入不能为空')

        time.sleep(5)

    # 测试邮箱登录       未激活
    def test_login_email_jihuo(self):
        drver = self.driver
        # 打开路径
        drver.get("http://localhost:8080/login")

        time.sleep(5)

        # 点击按钮
        drver.find_elements_by_class_name('van-tab__text')[1].click()

        time.sleep(5)

        # 标签选择器input标签
        drver.find_elements_by_tag_name('input')[2].send_keys('111111111@qq.com')

        # 点击按钮
        drver.find_elements_by_class_name('van-button')[2].click()

        # 获取弹框信息div
        div = drver.find_elements_by_class_name("van-toast__text")[0]
        #
        print(div)
        #
        # # 获取文本
        text = div.get_attribute('innerText')
        print(text)
        #
        # # 断言比对
        self.assertEqual(text, '登录请先去注册邮箱')

        time.sleep(5)

    # 测试邮箱登录       验证码不正确
    def test_login_email_yz(self):
        drver = self.driver
        # 打开路径
        drver.get("http://localhost:8080/login")

        time.sleep(5)

        # 点击按钮
        drver.find_elements_by_class_name('van-tab__text')[1].click()

        time.sleep(5)

        # 标签选择器input标签
        drver.find_elements_by_tag_name('input')[2].send_keys('2932746380@qq.com')

        # 点击按钮   获取验证码
        drver.find_elements_by_class_name('van-button')[1].click()

        # 标签选择器input标签    输入验证码
        drver.find_elements_by_tag_name('input')[3].send_keys('1111')

        # 点击
        drver.find_elements_by_class_name('van-button')[2].click()

        # 获取弹框信息div
        div = drver.find_elements_by_class_name("van-toast__text")[0]
        #
        print(div)
        #
        # # 获取文本
        text = div.get_attribute('innerText')
        print(text)
        #
        # # 断言比对
        self.assertEqual(text, '验证码错误,请重新输入')

        time.sleep(5)

    # 测试邮箱登录      登录成功
    def test_login_email_ok(self):
        drver = self.driver
        # 打开路径
        drver.get("http://localhost:8080/login")

        # time.sleep(5)

        # 点击按钮
        drver.find_elements_by_class_name('van-tab__text')[1].click()

        time.sleep(3)

        # 标签选择器input标签
        drver.find_elements_by_tag_name('input')[2].send_keys('2932746380@qq.com')

        # 点击按钮   获取验证码
        drver.find_elements_by_class_name('van-button')[1].click()

        # 标签选择器input标签    输入验证码
        # 获取弹框信息div
        yzm = drver.find_elements_by_class_name("van-toast__text")[0]
        text_yzm = yzm.get_attribute('innerText')
        print(yzm,'验证码')

        time.sleep(2)

        drver.find_elements_by_tag_name('input')[3].send_keys(text_yzm)

        time.sleep(2)

        # 点击
        drver.find_elements_by_class_name('van-button')[2].click()

        # 获取弹框信息div
        div = drver.find_elements_by_class_name("van-toast__text")[0]
        #
        print(div)
        #
        # # 获取文本
        text = div.get_attribute('innerText')
        print(text)
        #
        # # 断言比对
        self.assertEqual(text, '登录成功')

        time.sleep(5)




if __name__ == '__main__':
    # 构造测试集
    suite = unittest.TestSuite()

# 邮箱登录
    # # 测试用户非空
    # suite.addTest(User_LoginTest("test_login_email_null"))

    # # 测试用户未激活
    # suite.addTest(User_LoginTest("test_login_email_jihuo"))

    # 测试用户验证码不正确
    # suite.addTest(User_LoginTest("test_login_email_yz"))

    # 测试用户登录成功
    suite.addTest(User_LoginTest("test_login_email_ok"))


    # 进行测试
    runner = unittest.TextTestRunner()
    runner.run(suite)
